package com.yaoyong.yy_demo.module.springboot.inject;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 86188
 */
@SpringBootApplication
@RestController
@EnableConfigurationProperties(Author.class)
public class InjectApplication {
    public static void main(String[] args) {
        SpringApplication.run(InjectApplication.class, args);
    }

    @Autowired
    private Author author;


    @RequestMapping("/")
    public String index() {
        return "book author name is " + author.getName() + " ,author age is " + author.getAge();
    }

}

@ConfigurationProperties(prefix = "author")
class Author {
    private String name;
    private long age;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public long getAge() {
        return age;
    }

    public void setAge(long age) {
        this.age = age;
    }
}
